package com.xiangxiao.rpan.data.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.xiangxiao.rpan.data.enums.MessageTypeEnum;
import lombok.*;

import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 * @Projectname: rpan-data
 * @Author: xiangxiao
 * @Email: 573768011@qq.com
 * @Data:2024/6/3 0:45
 */
@Getter
@Setter
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class KafkaAlarm<T> {
  /**
   * 发送方
   */
  private String operator = "rpan-surveillance";

  /**
   * 方式
   */
  private String operation = "insert";

  /**
   * 发送时间
   */
  @JSONField(format = "yyyy-MM-dd HH:mm:ss")
  @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
  private Date time = new Date();

  /**
   * 类型
   */
  private String type;

  /**
   * 详细数据
   */
  private List<T> data;


  public KafkaAlarm(String type, List<T> data) {
    this.type = type;
    this.data = data;
  }

  public KafkaAlarm(MessageTypeEnum messageTypeEnum, T data) {
    this.type = messageTypeEnum.getMqttTopic();
    this.data = Collections.singletonList(data);
  }
}
